<?php
class Character {
	public $id = NULL;
	public $name;
	public $hp;
	public $pow;
	public $vit;
	public $spd;
	public $tec;

	function saveDb() {
		$conn = mysql_connect('localhost', 'root', '1234');
		mysql_select_db("phpgame");
		//$val1 = $this->name;
		//$val2 = $this->hp;
		//$val3 = $this->pow;
		//$val4 = $this->vit;
		//$val5 = $this->spd;
		//$val6 = $this->tec;

		if (id == null) {
			$sql = "INSERT INTO character (name, hp, pow, vit, spd, tec) VALUES ('" . $this->name . "', '" . $this->hp . "', '" . $this->pow . "', '" . $this->vit . "', '" . $this->spd . "', '" . $this->tec . "');";
			$this->id = mysql_insert_id();
		}
		
		else {
			$sql = "UPDATE character SET name='this->name', hp='this->hp', pow=this->pow, vit=this->vit, spd=this->spd, this->tec WHERE id=this->id;";
		}
		
		mysql_query($sql);
		
		return 'success';
	}

	function loadDb() {
		$conn = mysql_connect('localhost', 'root', '1234');
		mysql_select_db("phpgame");
		if (isset($id)) {
			$sql = "SELECT * from character WHERE $id='this->id'";
			mysql_query($sql);
		}
		
	}
	
	/*function saveSession() {
		$_SESSION['character'] = $this->id;
	}
	
	function loadSession() {
		$this->id = $_SESSION['character'];
		loadDb();
	}*/
	
	
	// saveDb()
	// if id = null insert
	// else update
	// mysql_query($sql);
	// $this->id = mysql_insert_id();

	// loadDb($id)
	// 'select char where id = ' . $id . ';';

	// saveSession()
	// $_SESSION['character'] = $this->id;

	// loadSession()
	// $this->id = $_SESSION['character'];
	// $this->loadDb();

	/*
	 public function loadAvatar ()
	 {
	$avatarPic = @imagecreatefrompng($avatar);
	if(!$avatarPic)
	{
	$defaultAvatar = $_player['defaultAvatar'];
	$avatarPic = @imagecreatefrompng($defaultAvatar);

	return $avatarPic;
	}

	function loadStats ()
	{
	public $pow = $_player["pow"];
	public $vit = $_player["vit"];
	public $agi = $_player["agi"];
	public $tec = $_player["tec"];
	public $hp = $_player["hp"];
	public $hpMax = $_player["hpMax"];
	public $job = $_player["job"];
	public $exp = $_player["exp"];

	return $pow,$vit,$agi,$tec,$hp,$hpMax,$job,$exp;
	}

	public function loadSkill ()
	{
	public $skill1 = $_player["skill1"];
	public $skill2 = $_player["skill2"];
	public $skill3 = $_player["skill3"];
	public $skill4 = $_player["skill4"];
	public $skill5 = $_player["skill5"];
	public $skill6 = $_player["skill6"];
	public $skill7 = $_player["skill7"];
	public $skill8 = $_player["skill8"];
	public $skill9 = $_player["skill9"];
	public $skill10 = $_player["skill10"];
	public $skill11 = $_player["skill11"];
	public $skill12 = $_player["skill12"];
	public $skill13 = $_player["skill13"];
	public $skill14 = $_player["skill14"];
	public $skill15 = $_player["skill15"];
	public $skill16 = $_player["skill16"];
	public $skill17 = $_player["skill17"];
	public $skill18 = $_player["skill18"];

	return $skill1,$skill2,$skill3,$skill4,$skill5,$skill6,$skill7,$skill8,$skill9,$skill10,$skill11,$skill12,$skill13,$skill14,$skill15,$skill16,$skill17,$skill18;
	}

	public function loadEquip ()
	{
	public $equipment1 = $_player["equipment1"];
	public $equipment2 = $_player["equipment2"];
	public $equipment3 = $_player["equipment3"];
	public $equipment4 = $_player["equipment4"];
	public $equipment5 = $_player["equipment5"];
	public $equipment6 = $_player["equipment6"];
	public $equipment7 = $_player["equipment7"];
	public $equipment8 = $_player["equipment8"];
	public $equipment9 = $_player["equipment9"];
	public $equipment10 = $_player["equipment10"];

	return $equipment1,$equipment2,$equipment3,$equipment4,$equipment5,$equipment6,$equipment7,$equipment8,$equipment9,$equipment10;
	}

	public function loadInventory ()
	{
	public $inventory1 = $_player["inventory1"];
	public $inventory2 = $_player["inventory2"];
	public $inventory3 = $_player["inventory3"];
	public $inventory4 = $_player["inventory4"];
	public $inventory5 = $_player["inventory5"];
	public $inventory6 = $_player["inventory6"];
	public $inventory7 = $_player["inventory7"];
	public $inventory8 = $_player["inventory8"];
	public $inventory9 = $_player["inventory9"];
	public $inventory10 = $_player["inventory10"];

	return $inventory1,$inventory2,$inventory3,$inventory4,$inventory5,$inventory6,$inventory7,$inventory8,$inventory9,$inventory10;
	}
	*/
}

$character = new Character();
$character->name = $_POST['name'];
//...
$result = $character->saveDb();
echo $html;
?>